<template>
  <div>
    <preHeader></preHeader>
    <div class="top-block"></div>
    <mt-field label="登录器地址" placeholder="请输入地址" v-model="area"></mt-field>
    <mt-button v-if='type==0' @click='addArea()'>添加</mt-button>
    <mt-button v-else @click='changeArea()'>修改</mt-button>
  </div>
</template>

<script>
  import {get_orders,login_launcher_list,login_launcher_edit,login_launcher_add} from '@/api/';
  export default {
    data(){
      return{
        tel:'',
        type:'0',//添加或者修改
        area:'',//地址
      }
    },
    methods:{
       getServer(){//获取信息
         this.tel = JSON.parse(localStorage.getItem('tel'));
         login_launcher_list({tel:this.tel}).then(res =>{
           // console.log(res)
           this.type = res.status;
           this.area = res.data.url;
         })
       },
      addArea(){//添加地址
        login_launcher_add({tel:this.tel,url:this.area}).then( res=>{
          // console.log(res)
          if(res.status == 0){
            this.$messagebox.alert(res.msg)
          }else{
            this.$messagebox.alert('添加成功!').then(action => {
              if(action == 'confirm'){
                this.$router.push('/active');
              }
            });
          }
        })
      },
      changeArea(){//修改
        login_launcher_edit({tel:this.tel,url:this.area}).then(res =>{
          if(res.status == 0){
            this.$messagebox.alert(res.msg)
          }else{
            this.$messagebox.alert('修改成功!').then(action => {
              if(action == 'confirm'){
                this.$router.push('/active');
              }
            });
          }
        })
      }


    },
    mounted() {
      this.getServer();
    }
  }
</script>

<style scoped>
  .mint-cell{margin-top: 10em;border-bottom: 1px solid #ccc;margin-bottom: 2em;}
 /deep/ .mint-cell-wrapper{background-image:none}
.mint-button{background-color: #2f3953;color: #fff;width: 150px;border-radius: 20px;margin-left: 50%;transform: translateX(-50%);}
</style>
